<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});


//Route::get('foo', function () {
//    return 'bar';
//});


// 匹配 get、post method
/*
Route::match(['get', 'post'], 'foo', function () {
    return 'bar -> get or post.';
});*/


/*
Route::any('foo', function () {
    return 'any method.';
});*/


// 默认是 302
//Route::redirect('foo1', 'foo');

//Route::redirect('foo2', 'foo', 301);

// 可以实现 301 跳转
//Route::permanentRedirect('foo3', 'foo');


/////////////// 视图路由 ///////////////

//Route::view('foo4', 'welcome');

// 传递参数
//Route::view('foo4', 'welcome', ['name' => 'laravel6.5']);

/////////////// 路由参数 ///////////////

// id 参数为必填
//Route::get('user/profile/{id}', function ($id) {
//    return $id;
//});

//Route::get('user/{name?}', function ($name = null) {
//    return $name;
//});

// name 为可选参数，参数不存在时,使用默认的参数
//Route::get('user/{name?}', function ($name = 'laravel') {
//    return $name;
//});

/////////////// 命名路由 ///////////////

//Route::get('user/profile/{id}', function ($id) {
//    return 'user/profile/' . $id;
//})->name('profile');


/*Route::get('foo', function () {
//    生成路由
//    route('profile');

//    重定向到生成的路由, 并携带id参数，id会自动赋值到目标路由中.
    return redirect()->route('profile', ['id' => 200]);
});*/

// 会查询数据库
//Route::get('foo/{user}', function (App\User $user){
//    dd($user);
//});


///////////////////  view ///////////////////

//Route::get('v/foo', function () {
//    return view('v_foo');
//});


// 单个行为控制 不需要指明方法
// -> middleware('xx') 指定中间件
use Illuminate\Http\Request;

Route::get('c/user/profile', 'ShowProfileController');//->middleware('auth');

// 资源控制器
Route::resource('photos', 'PhotoController');

////////////////////// work  //////////////////////
Route::get('bca01', function () {


    $data = <<<data
        
zhenyu sun<br/>
Dhl@123#<br/>

20679<br/>
souvi.user@dhl.com<br/>
    
http://23.158.246.72:8802/bca-admin/login <br/>

http://23.158.246.72:8802/bca-admin/fromcrm/bcacreate?contractNo=A000019<br/>
http://23.158.246.72:8802/bca-admin/fromcrm/bcacreate?opportunityNo=Z001040<br/>
data;

    return $data;
});

Route::get('bca02', function () {
    return 'https://aux.dhl.com/bca-admin/login';
});

Route::get('bca_sql', function () {

    $sql = <<<data

select a.* from system_role a left join system_post_role b on a.id = b.role_id left join system_staff_post c on c.post_id = b.post_id left join system_staff d on d.id = c.staff_id left join system_user e on d.staff_code = e.login_name where a.status = '1' and e.id = ? or b.post_id = ? 

data;
    return $sql;

});

/////////// upload
Route::get('/upload', 'UploadController@index');
Route::post('/upload', 'UploadController@uploadFile');


Route::any('hello/{message}', 'HelloController@hello');
Route::any('hello2', 'HelloController@hello2');
Route::any('hello3', 'HelloController@hello3');

/*
Route::get('hello_ip', function(Request $request){
    $ips = $request->getClientIps();
//    $ip = $request->ip();

    $ip = request()->ip();
    dd($ips, $ip);
});*/

Route::get('dl/crm', function () {
    return response()->download(storage_path('app/bca/guns-test-20200107.sql'), 'guns-test-20200107.sql');
});

Route::get('dl/u', function () {
    return response()->download(storage_path('app/bca/bca-framework-3.0.jar'), 'bca-framework-3.0.jar');
});

Route::get('dl/r1', function () {
    return response()->download(storage_path('app/bca/r1.xlsx'), 'r1.xlsx');
});


// 丰信授权
Route::get('ok', function (){
    $clientId = "sentinel_userinfo_client";

    $appid = 'wxb55bbff809206d06';


    $url = 'https://h6.fengxinacerp.com/fxhome/index.html?unionid=[(${unionid})]&openid=[(${openid})]';
    $url = base64_encode($url);
    $redirect = "https://h6.fengxinacerp.com/wechat-oauth-server/oauth2/{$appid}/?clientId={$clientId}&url={$url}";

    $redirect = urlencode($redirect);

    // 授权
    echo "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$redirect}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";

});
